package servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.SistemaCVR;
import xml.SerializadorCotizacion;
import xml.SerializadorOrdenCompra;
import xml.XmlUtil;
import bean.vo.CotizacionVO;
import bean.vo.OrdenCompraVO;

/**
 * Servlet implementation class ProcesarPedPendientes
 */
public class ProcesarPedPendientes extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProcesarPedPendientes() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		try {
			List<OrdenCompraVO> ordenesCompra = SistemaCVR.generarOrdenesDeCompraParaNuevosPedidos();
			
			if(ordenesCompra.isEmpty()){
				session.setAttribute("mensaje", "No se encontraron ordenes de comprar a procesar");
				session.setAttribute("ordenesCompra", new ArrayList<OrdenCompraVO>());
			}else{
				session.setAttribute("mensaje", "");
				session.setAttribute("ordenesCompra", ordenesCompra);
			}
		} catch (Exception e) {
			session.setAttribute("mensaje", "Se produjo un error al procesar las ordenes de compra");
		}finally{
			RequestDispatcher dispatcher = request.getRequestDispatcher("/resultadoOrdenesCompra.jsp");
			dispatcher.forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
